package logic

import (
	"context"
	"errors"
	"gorm.io/gorm"
	"wei/models/mysql"

	"wei/weirpc/internal/svc"
	"wei/weirpc/weirpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *weirpc.PerfectRequest) (*weirpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Model:    gorm.Model{ID: uint(in.UserId)},
		Account:  in.Account,
		Password: in.Password,
		Age:      int(in.Age),
		Jg:       in.Jg,
		Email:    in.Email,
		Image:    in.Image,
	}
	mysql.DB.Debug().Where("id=?", in.UserId).Updates(&user)
	if in.UserId == 0 {
		return nil, errors.New("用户不存在")
	}

	return &weirpc.PerfectResponse{}, nil
}
